package com.yfeng.quartz;

import java.text.ParseException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

public class TaskScheduler {

  private Log log = LogFactory.getLog(TaskScheduler.class);
	
	private static Scheduler scheduler;
	
	public void init(){
		try {
			scheduler=StdSchedulerFactory.getDefaultScheduler();
			scheduler.start();
			
			JobDetail jobDetail = new JobDetail("scanScheduler", Scheduler.DEFAULT_GROUP, com.yfeng.quartz.job.CacheJob.class);

			CronTrigger trigger = new CronTrigger("scanSchedulerTrigger", null, "0 0/2 * ? * *");
			
			scheduler.scheduleJob(jobDetail, trigger);
			
		} catch (SchedulerException e) {
			log.error(e.getMessage(),e);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
